/**
 * @author Mabel Zhang
 */


import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import java.util.Vector;

import au.com.bytecode.opencsv.CSVReader;


public class PopulateSpots
{
  Vector<Spot> spots = new Vector<Spot> ();
  
  PopulateSpots ()
  {
    populateData (); 
  }
  
  void populateData ()
  {
    final int CKT = 0;
    final int MMID = 1;
    final int ST = 2;
    final int STFROM = 3;
    final int STTO = 4;
    final int DIR = 5;
    
    String fileName = "ParkitSetup.csv";
    
    // Read CSV file
    CSVReader reader;
    try
    {
      reader = new CSVReader(new FileReader(fileName));
    }
    catch (FileNotFoundException e)
    {
      System.err.printf ("CSV file %s not found.\n", fileName);
      return;
    }
    
    String [] nextLine;
    try
    {
      while ((nextLine = reader.readNext()) != null)
      {
        if (nextLine.length > 2)
        {
          if ((! nextLine[ST].isEmpty()) && (! nextLine[STFROM].isEmpty()) && (! nextLine[STTO].isEmpty()))
          {            
            // nextLine[] is an array of values from the line
//            System.out.println ("At " + nextLine[ST] + ", from " + nextLine[STFROM] + ", from " + nextLine[STTO] + "etc...");
            
//            System.err.println (nextLine[ST]);
            try
            {
              int mm = Integer.parseInt (nextLine[MMID]);

              Spot sp = new Spot (mm, nextLine[ST], nextLine[STFROM], nextLine[STTO]);
              spots.add (sp);
            }
            catch (NumberFormatException e)
            {
              System.err.println ("Not an integer.");
            }

          }
        }
      }
    }
    catch (IOException e)
    {
      System.err.println ("Error while reading the CSV file.");
      return;
    }
    
    
  }

  
  Vector<Spot> getSpots ()
  {
    return spots;
  }


}
